windowloads()
getspumber()
getname ()

function outlogin(){outloginfn()}
var divbox = $('.content .type_area')[0]

var page = 1
var flag = true

function getData(){
    if(!flag){
        return
    }
    flag = false
    sendAjax({
        url:'goods/api/list/'+page,
        success: res => {
            let data = res.data.goodslist
            if(res.data.goodslist.length<12){
                    return
                }
                for(var item in data){
                    var div = `
                    <div>
                    <a href="detail.html?id=${data[item]._id} " target = "_blank"  id="hrefbox">
                        <div id="img-wrapper">
                            <img src="${data[item].goodsimg1}" title="${data[item].goodsname}">
                        </div>
                        <div class="top">
                            <p  title="${data[item].goodsname}">${data[item].goodsname}</p>
                        </div>
                        <div class="buttom">
                            <span>￥${parseInt(Math.random()*5000)+1000}</span>
                        </div>
                    </a>
                    </div>   
                    `
                divbox.innerHTML += div    
                }
            page++
            flag = true
        }
       })
}

getData()

// 懒加载
window.onscroll = function(){
    var bootombox = document.querySelectorAll('.content .type_area >div')
    var botmbox = bootombox[bootombox.length-1]
    var domtop =  document.body.scrollTop || document.documentElement.scrollTop 
        if(domtop+window.innerHeight > botmbox.offsetTop+200){
            getData()
        }
    if (domtop > 450) {
        $('#left_navigation')[0].style =
            ' position: fixed;right: 80px; top: 80px; ';
    } else if (domtop < 450) {
        $('#left_navigation')[0].style =`
        position: absolute;
        width: 58px;
        height: 294px;
        right: -85px;
        top: 55px;
        z-index: 100;
        background-color: #fff;
        border-radius: 10px;
        `
    }


}

var mySwiper = new Swiper('.swiper', {
    direction: 'horizontal', 
    loop: true, 

    pagination: {
        el: '.swiper-pagination',
        clickable: true
    },

    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    autoplay: true, 
})

// 鼠标移入时停止自动轮播
mySwiper.el.onmouseover = function () {
    mySwiper.autoplay.stop()
}
// 鼠标移出后开启自动轮播
mySwiper.el.onmouseout = function () {
    mySwiper.autoplay.start()
}

